﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; 
using MINERP.DAL.Statistics;

namespace MINERP.Statistics
{
    public partial class FrmProductStat : Form
    {
        private List<MODEL.Statistics.Shop_Info> ListShop = new List<MINERP.MODEL.Statistics.Shop_Info>();    //商户集合 
        private BLL.Statistics.StatisticsBLL SSBLL = new MINERP.BLL.Statistics.StatisticsBLL();

        public FrmProductStat()
        {
            InitializeComponent();
        }

        private void FrmProductStat_Load(object sender, EventArgs e)
        {
            BindShop();
            dateEdit2.DateTime = DateTime.Now;
            dateEdit1.DateTime = DateTime.Now;
        }

        private void GetShopList()
        {
            ListShop.Clear();
            ListShop = SSBLL.GetShopList();
        }

        #region 设置商户下拉列表
        /// <summary>
        /// 设置商户下拉列表
        /// </summary>
        private void BindShop()
        {
            if (comboBoxEdit1.Properties.Items != null)
                comboBoxEdit1.Properties.Items.Clear();

            GetShopList();
            foreach (MINERP.MODEL.Statistics.Shop_Info s in ListShop)
            {
                comboBoxEdit1.Properties.Items.Add(s.ShopName);
            }
            comboBoxEdit1.Text ="--请选择--";
        }
        #endregion 

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            simpleButton1.Enabled = false;
            this.Cursor = Cursors.WaitCursor;
            if (comboBoxEdit1.Text == "--请选择--")
            {
                simpleButton1.Enabled = true;
                return;
            }
            DateTime startTime = dateEdit1.DateTime.Date;
            DateTime endTime = dateEdit2.DateTime.Date;
            if (startTime > endTime)
            {
                simpleButton1.Enabled = true;
                return;
            }
            int shopId = 0;
            string shopName = comboBoxEdit1.Text.Trim();
            foreach (MINERP.MODEL.Statistics.Shop_Info s in ListShop)
            {
                if (s.ShopName == shopName)
                {
                    shopId = s.ShopID;
                    break;
                }
            }
            if (shopId == 0)
            {
                simpleButton1.Enabled = true;
                return;
            }

           DataSet ds=  ProductStatDAL.GetProductStat(shopId, startTime, endTime);
           ds.WriteXml(@"C:\Windows\xmldata\PrintProductStat.xml", XmlWriteMode.WriteSchema);

           report1.Preview = previewControl1;
           report1.Load(Application.StartupPath + "\\RpProductStat.frx");
           report1.RegisterData(ds);
           report1.SetParameterValue("shopName", shopName);
           report1.SetParameterValue("startTime", startTime);
           report1.SetParameterValue("endTime", endTime);
           previewControl1.Refresh();
           previewControl1.Show();
           report1.Show();
           this.Cursor = Cursors.Default;
           simpleButton1.Enabled = true;
        }

    }
}
